#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef short int bool;
#define true    1
#define false   0


#define N 4

char chess[N][N];
short int path[N] = {-1};
int n = 0;
int max = 0;

void init()
{
    int i = 0, j = 0;

    for(i = 0; i < N; i++)
    {
        for(j = 0; j < N; j++)
        {
            chess[i][j] = '.';
        }
    }
    memset(path, -1, sizeof(path[0])*N);
    n = 0;
    max = 0;
}

void showchess()
{
    int i = 0, j = 0;

    for(i = 0; i < n; i++)
    {
        for(j = 0; j < n; j++)
        {
            printf("%c ", chess[i][j]);
        }
        printf("\n");
    }
    printf("-------------\n");
}

bool canplace(int x, int y)
{
    int i = 0, j = 0;

    if(chess[x][y] == 'X')
    {
        return false;
    }

    for(i = x-1; i >= 0; i--)
    {
        if(chess[i][y] == 'X')
        {
            break;
        }
        else if(chess[i][y] == '@')
        {
            return false;
        }
        else
        {

        }
    }
    for(j = y-1; j >= 0; j--)
    {
        if(chess[x][j] == 'X')
        {
            break;
        }
        else if(chess[x][j] == '@')
        {
            return false;
        }
        else
        {

        }
    }
    return true;
}

void fn(int x, int y, int count)
{
    //showchess();
    if(x >= n || y >= n)
    {
        //printf("count:%d\n", count);
        max = max < count ? count : max;
        return;
    }
    if(canplace(x, y) == true)
    {
        chess[x][y] = '@';
        fn(x + (y+1) / n, (y+1) % n, count+1);
        chess[x][y] = '.';
    }
    fn(x + (y+1) / n, (y+1) % n, count);
}

void process()
{
    //showchess();

    fn(0, 0, 0);

    printf("%d\n", max);

}

int main()
{
    //freopen("bin\\debug\\in.txt", "r", stdin);
    int i = 0, j = 0;
    char line[N+1];

    while(1)
    {
        init();
        scanf("%d", &n);
        if(n == 0)
        {
            break;
        }
        for(i = 0; i < n; i++)
        {
            scanf("%s", line);
            for(j = 0; j < n; j++)
            {
                chess[i][j] = line[j];
            }
        }
        process();
    }

    return 0;
}
